const api = require("../../../config/api");

// pages/MyPage/MyEstimations/MyEstimations.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    psCustomerCode:'',
    estimationList:[],
    pageNum:1,
  },
  onBack() {
    wx.navigateBack({
      delta: 1
    });
  },

  onMyEstimation: function (e) {
    wx.navigateTo({
      url: '/pages/MyPage/MyEstimation/MyEstimation',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //查询
    this.fetchEstimationData();
  },

  fetchEstimationData: function () {
    wx.getStorage({
      key: 'psCustomerCode',
      success: (res) => {
        this.setData({
          psCustomerCode: res.data
        });
        wx.request({
          url: api.estimationData,
          method: 'POST',
          data: {
            evaluateSourceCode:res.data,
            pageNum:this.data.pageNum,
            pageSize:"5",
            evaluateSource:1,
          },
          success: (res) => {
            wx.hideLoading()
            if (res.data.code == 200) {
              const resData = res.data.data.rows;
              if (resData.length!=0) {
                this.setData({
                  pageNum: this.data.pageNum + 1,
                });
              }
              this.setData({
                estimationList:  [...this.data.estimationList, ...resData]
              });
            } else {
              wx.showToast({
                title: res.data.mesage,
                icon: "none"
              })
            }
          }
        })
      },
    });
  },
  // 滑到底部
  onScrollToLower: function( ){
    console.log('滑到末尾，刷新')
    this.fetchEstimationData()
  },
  // 重新获取数据
  onScrollToUpper: function () {
    console.log('刷新')
    this.resetData()
  },
  resetData: function () {
     //查询
     this.setData({
      pageNum:1,
      estimationList: [],
    })
    this.fetchEstimationData();
  }
})